<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery/jquery.js"></script>
    <script src="../js/plugins/jquery-form/jquery.form.js"></script>
    <script src="../js/plugins/js-cookie/js.cookie.min.js"></script>
    <script src="../js/vue/common.js"></script>
</head>
<body>
<form id="_j_login_form" method="post">
    账号:<input name="username" type="text">
    密码:<input name="password" type="password">
    <input id="_js_loginBtn" type="button" value="登录">
</form>


<script>
    $('#_js_loginBtn').click(function(){
        $("#_j_login_form").ajaxSubmit({
            url: "http://localhost:8080/users/login",
            type: "POST",
            success: function (data) {
                console.log(data);
                if (data.code == 200) {
                    var map = data.data;
                    var token = map.token;  //后续后端获取当前登录用户信息
                    var user = map.user;  //前端页面需要显示用户信息

                    Cookies.set('user', JSON.stringify(user), { expires: 1/48,path:'/'});
                    Cookies.set('token', token, { expires: 1/48,path:'/'});

                    location.href='/views/index.html';
                } else {
                    alert(data.msg);
                }
            }
        })
    })
</script>

</body>
</html>